<!DOCTYPE html>
<html>
<head>
    <include file="Public:header" />
    <!-- jqgrid-->
    <link href="__ACSS__/plugins/jqgrid/ui.jqgrid.css?0820" rel="stylesheet">
    <!-- Data picker -->
    <link href="__ACSS__/plugins/datapicker/datepicker3.css" rel="stylesheet">
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox ">
                    <div class="ibox-content">
                    	<div class="ibox-search-box">
                    		<div class="row">
	                    		<div class="infont col-md-2">
									<input type="hidden" name="shop_id" class="form-control" value="<{$shop_id}>">
		                    		<input type="text" name="register_tel" class="form-control" placeholder="用户名(手机号)">
								</div>
								<div class="infont col-md-2">
		                    		<input type="text" name="code" class="form-control" placeholder="订单编号">
								</div>
								<div class="infont col-md-2">
									<select name="status" class="form-control" placeholder="订单状态">
										<option value="">请选择</option>
										<option value="0">申请退款</option>
										<option value="-3">拒绝退款</option>
										<option value="-2">同意退款</option>
										<option value="-1">失效</option>
										<option value="1">未付款</option>
										<option value="2">已付款</option>
										<option value="3">配送中</option>
										<option value="4">完成</option>
									</select>
								</div>
								<div class="input-daterange" id="datepicker">
									<div class="infont col-md-2">
			                    		<input type="text" name="create_time_begin" class="form-control" readonly="readonly" value="<{:date('Y-m-d', strtotime('-7 days'))}>" placeholder="下单时间(开始)">
									</div>
									<div class="infont col-md-2">
			                    		<input type="text" name="create_time_end" class="form-control" readonly="readonly" value="<{:date('Y-m-d')}>" placeholder="下单时间(结束)">
									</div>
								</div>
								<div class="infont col-md-2">
									<select name="pay_type" class="form-control" placeholder="支付类型">
										<option value="0">请选择</option>
										<option value="1">支付宝</option>
										<option value="2">微信</option>
										<option value="3">余额</option>
									</select>
								</div>
								<div class="infont col-md-2">
									<select name="mail_type" class="form-control" placeholder="配送类型">
										<option value="0">请选择</option>
										<option value="1">校园模式</option>
										<option value="2">快递模式</option>
									</select>
								</div>
	                    		<div class="infont col-md-2">
	                    			<button class="btn btn-success btn-block btn-ibox-search" type="button">搜索</button>
	                    		</div>
	                    		<div class="infont col-md-4">
	                    			温馨提示：你还有<font style="color:red; font-size:20px;"><{$count}></font>个退款订单未处理！
	                    		</div>
                    		</div>
                    	</div>
                        <div class="jqGrid_wrapper">
                            <table id="table_list"></table>
                            <div id="pager_list"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<!-- 全局js -->
<include file="Public:foot" />
<!-- jqGrid -->
<script src="__AJSPLUGINS__/jqgrid/i18n/grid.locale-cn.js?0820"></script>
<script src="__AJSPLUGINS__/jqgrid/jquery.jqGrid.min.js?0820"></script>
<!-- Page-Level Scripts -->
<!-- Data picker -->
<script src="__AJSPLUGINS__/datapicker/bootstrap-datepicker.js"></script>
<script>
$(document).ready(function () {
	var params = "?";
	params += "create_time_begin" + "=" + $("input[name=create_time_begin]").val();
	params += "&";
	params += "create_time_end" + "=" + $("input[name=create_time_end]").val();
	var shop_id = $("input[name=shop_id]").val();
	if(shop_id!=0 && shop_id!=""){
		params += "&";
		params += "shop_id" + "=" +shop_id;
	}
	//初始化
    $.jgrid.defaults.styleUI = 'Bootstrap';
    $("#table_list").jqGrid({
    	url : '__URL__/getAllData' + params,
    	datatype: "json",
        height: 580,
        autowidth: true,
        shrinkToFit: true,
        rowNum: 20,
        rowList: [20, 30, 50,100,200],
        colNames: ['ID', '订单编号', '用户名', '店铺', '支付方式', '下单时间','实付款','提成','配送类型', '状态', '操作'],//'下单时间',
		colModel: [ {name : 'id',index : 'id'},
                    {name : 'code',index : 'code'},
                   	{name : 'register_tel',index : 'register_tel'},
					{name : 'shop_name',index : 'shop_name',formatter : function(cellvalue, options, rowObject){
						var content = rowObject.school_name+rowObject.shop_name;
						return content;
					}},
					{name : 'pay_type',index : 'pay_type',formatter : function(cellvalue, options, rowObject){
						var content = "";
						if(cellvalue == 1) {
							content = '支付宝';
						}else if(cellvalue == 2){
							content = '微信';
						}else if(cellvalue == 3){
							content = '余额';
						}
						return content;
					}},
					{name : 'create_time',index : 'create_time',formatter : function(cellvalue, options, rowObject){
						var content = rowObject.create_time;
						return content;
					}},
                   	{name : 'real_price',index : 'real_price',formatter : function(cellvalue, options, rowObject){
                   	 	return (parseFloat(cellvalue) + parseFloat(rowObject.mail_fee)).toFixed(2);
              	 	}},
					{name : 'commission',index : 'commission',formatter : function(cellvalue, options, rowObject){
						return parseFloat(rowObject.commission).toFixed(2);
					}},
              	 	{name : 'mail_type',index : 'mail_type',formatter : function(cellvalue, options, rowObject){
              	 		var content = "";
              	 		if(cellvalue == 1) {
                      		content = '校园模式';
              	 		}else if(cellvalue == 2){
              	 			content = '快递模式';
              	 		}
                   	 	return content;
              	 	}},
                   	/* {name : 'create_time',index : 'create_time',formatter: 'date',formatoptions: {srcformat:'u',newformat:'Y-m-d H:i:s'}}, */
                   	{name : 'status',index : 'status',formatter : function(cellvalue, options, rowObject){
                   		if(cellvalue == -3) {
                      		content = '拒绝退款';
                      	}else if(cellvalue == -2) {
                      		content = '同意退款';
                      	}else if(cellvalue == -1) {
                      		content = '失效';
                      	}else if(cellvalue == 0) {
                      		content = '申请退款';
                      	}else if(cellvalue == 1) {
                     		content = '未付款';
                     	}else if(cellvalue == 2) {
                     		content = '已付款';
                     	}else if(cellvalue == 3) {
                     		content = '配送中';
                     	}else if(cellvalue == 4) {
                     		content = '完成';
                     	}else{
                     		content = '未知';
                     	}
                   	 	return content;
              	 	}},
              	 	{name : 'id',index : 'id',sortable : false,formatter : function(cellvalue, options, rowObject){
	                   	 content = '';
                   		 content += ' <button class="btn btn-default btn-xs btn-outline" onclick="printThis('+ rowObject.id +')"><i class="fa fa-print"></i>  打印</button>';
                   		 content += ' <button class="btn btn-default btn-xs btn-outline" onclick="printmail('+ rowObject.id +')"><i class="fa fa-print"></i>  打印快递单</button>';
	                   	 if(rowObject.status == 2){
	                   		content += ' <button class="btn btn-white btn-xs btn-outline" onclick="updateStatus('+ rowObject.id +','+ 3 +')"><i class="fa fa-send"></i>  已发货</button>';
	                   	 }
	                   	 if(rowObject.status == 3){
	                   		content += ' <button class="btn btn-white btn-xs btn-outline" onclick="updateStatus('+ rowObject.id +','+ 4 +')"><i class="fa fa-send"></i>  完成订单</button>';
	                   	 }
	                   	 if(rowObject.status == 0){
	                   		content += ' <button class="btn btn-white btn-xs btn-outline" onclick="cancelOrder('+ rowObject.id +','+ rowObject.pay_type +')"><i class="fa fa-close"></i>  同意退款</button>';
	                   		content += ' <button class="btn btn-white btn-xs btn-outline" onclick="updateStatus('+ rowObject.id +','+ -3 +')"><i class="fa fa-close"></i>  拒绝退款</button>';
	                   	 }
	                   	if(rowObject.status == -3){
	                   		content += ' <button class="btn btn-white btn-xs btn-outline" onclick="updateStatus('+ rowObject.id +','+ 4 +')"><i class="fa fa-send"></i>  完成订单</button>';
	                   	 }
	                   	 return content;
	               	 }}
                  ],
        pager: "#pager_list",
        viewrecords: true,
        hidegrid: false,
        sortname: "id",
        sortorder: "desc",
        ondblClickRow: function(rowid) {
        	if(rowid != null) {
        		layerDialog("详细",'__URL__/detailView?id='+rowid,"90%","90%",true);
        	}else {
        		layer.msg("您没有选取数据！");
        	}
        }
    });
    
    
    //搜索
    $(".btn-ibox-search").click(function() {
    	result = getSearchParamByInput();
    	$("#table_list").jqGrid('setGridParam', {
    		page: 1,
    		url : '__URL__/getAllData' + result
    	}).trigger("reloadGrid");
    })
    //监控回车
    $(".ibox-search-box").find(":input").keydown(function(event) {
		if(event.keyCode == 13){
			$(".btn-ibox-search").trigger("click");
		}
	})
    
    //获取搜索条件（仅限封装简单条件）
    function getSearchParamByInput() {
    	var result = "";
    	$(".ibox-search-box").find(":input").each(function() {
    		if($(this).val() != "") {
    			if(result != "") {
    				result += "&";
    			}else{
    				result += "?";
    			}
    			result += $(this).attr("name") + "=" + $(this).val();
    		}
    	})
    	return result;
    }
	
 	// 设置按钮
    $("#table_list").jqGrid('navGrid', '#pager_list', {
        edit: false,
        add: false,
        del: false,
        search: false
    }, {
        height: 200,
        reloadAfterSubmit: true
    }).navButtonAdd('#pager_list',{
 	    caption:"导出excel", 
	    title:"导出excel",
	    buttonicon:"fa fa-file-excel-o",   
	    onClickButton: function(){   
		   result = getSearchParamByInput();
		   var url = "__URL__/outExcel" + result;
		   var iframe = document.createElement("iframe");
		   iframe.src = url;
		   iframe.style.display = 'none';
		   document.body.appendChild(iframe);
		   layer.msg("正在导出excel，请稍后...");
	    },
	    position:"last"  
	});
    // 添加适配响应
    $(window).bind('resize', function () {
        var width = $('.jqGrid_wrapper').width();
        $('#table_list').setGridWidth(width);
    });
	
    //Data picker
    $('.input-daterange').datepicker({
        keyboardNavigation: false,
        forceParse: false,
        autoclose: true,
        todayHighlight: true
    });
});
//更改状态
function updateStatus(id,status){
	layer.confirm('是否执行？', function(index){
		$.ajax({
			url:"__URL__/updateStatus",
			type:"post",
			data:{'id':id,'status':status},
			success:function(json){
				var data = eval("("+json+")");
				if(data.status == 1){
					layer.msg("处理成功！", {time: 1000});
				}else{
					layer.msg("处理失败！", {time: 1000});
					$('#table_list').trigger("reloadGrid");
				}
				$('#table_list').trigger("reloadGrid");
			}
		})
		layer.close(index);
	})
}

function cancelOrder(id,paytype){
	if(paytype == 1){
		//支付宝
		layerDialog("同意退款【支付宝】",'__URL__/cancelOrder?orderId='+id,"90%","90%",true);
	}else if(paytype == 2){
		//微信支付
		layerDialog("同意退款【微信】",'__URL__/cancelOrder?orderId='+id,"70%","70%",true);
	}else if(paytype == 3){
		//余额支付
		layerDialog("同意退款【余额】",'__URL__/cancelOrder?orderId='+id,"70%","70%",true);
	}
}

function printThis(id){
	layerDialog("打印订单",'__URL__/printView?orderId='+id,"90%","90%",true);
}
function printmail(id){
	layerDialog("打印订单",'__URL__/printmailView?orderId='+id,"30%","90%",true);
}
</script>
</html>